package org.example.todo.controller;

import org.example.todo.entity.TodoEntity;
import org.example.todo.model.Result;
import org.example.todo.service.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/todo")
public class TodoController {
    @Autowired
    private TodoService todoService;

    @GetMapping("/all")
    public Result<List<TodoEntity>> queryAll() {
        return todoService.queryAll();
    }

    @GetMapping("/{id}")
    public Result<TodoEntity> queryById(@PathVariable("id") Long id) {
        return todoService.queryById(id);
    }

    @PutMapping("/")
    public Result<?> update(@RequestBody TodoEntity todoEntity) {
        return todoService.updateTodo(todoEntity);
    }

    @PostMapping("/")
    public Result<?> add(@RequestBody TodoEntity todoEntity) {
        return todoService.addTodo(todoEntity);
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Long id) {
        return todoService.deleteTodo(id);
    }
}
